﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;

public class HotfixController : MonoBehaviour
{

	public LuaEnv luaEnv;

	// Start is called before the first frame update
	void Start() {
		luaEnv = new LuaEnv();
		luaEnv.AddLoader(luaFileLoader);    // 2.
		luaEnv.DoString("require 'tower' "); // 1.执行
	}

	/// <summary>
	/// 补丁文件读取器
	/// </summary>
	/// <param name="filepath"></param>
	/// <returns></returns>
	private byte[] luaFileLoader(ref string filepath) {
		string path = Application.persistentDataPath + "/" + filepath + ".lua";
		string content = System.IO.File.ReadAllText(path);
		Debug.Log(content);
		return System.Text.Encoding.UTF8.GetBytes(content);
	}

	private void OnDestroy() {
		if (luaEnv != null) {

			luaEnv.DoString("require 'tower.Dispose' ");
			luaEnv.Dispose();
		}
	}
}
